﻿CREATE FUNCTION [Utilities].[IsBit]
(
	@iTestBit INT
)
RETURNS BIT
AS
BEGIN
	-- This function will take an integer and return true if it is a bit value, i.e. 1, 2, 4, 8
	DECLARE @Result BIT;

	IF @iTestBit = 1
		-- Special case of TestBit = 1
		SET @Result = 1;
	ELSE IF ROUND(LOG(@iTestBit)/LOG(2),1) = LOG(@iTestBit)/LOG(2)
		-- if the LOG Base 2 of the TestBit value is an INTEGER, you have found 2, 4, 8, 16
		SET @Result = 1;
	ELSE
		SET @Result = 0;

	RETURN @Result;
END;
